import {
  RadarOverlay
} from './overlay'
export default {
  data() {
    return {
      center: {
        lng: 116.41338,
        lat: 39.91092
      },
      defaultCenter: {
        lng: 116.41338,
        lat: 39.91092
      },
      defaultZoom: 10,
      vertexPoint: null,
      zoom: 12,
      ZOOMBOUNDARY: 15,
      mapInit: null,
      _point: null,
      _title: null,
      _text: null,
      _statisticsText: null,
      _map: null,
      _div: null,
      _num: null,
      _showType: null,
    }
  },
  mounted() {
    this.initMap()
  },
  methods: {
    initMap() {
      let me = this;
      me.mapInit = new BMapGL.Map("groundMap");
      me.mapInit.centerAndZoom(me.defaultCenter, me.defaultZoom);
      //开启鼠标滚轮缩放
      me.mapInit.enableScrollWheelZoom(true)
      var scaleCtrl = new BMapGL.ScaleControl(); // 添加比例尺控件
      me.mapInit.addControl(scaleCtrl);
      var zoomCtrl = new BMapGL.ZoomControl(); // 添加缩放控件
      me.mapInit.addControl(zoomCtrl);
      me.mapInit.setMinZoom(9.5);
      //默认获取统计数
      me.getStatistics()
      //地图拖拽
      me.mapInit.addEventListener('dragend', function(e) {
        me.clearAllOverlays()
        me.vertexPoint = me.mapInit.getBounds().getSouthWest();
        me.center = me.mapInit.getCenter();
        if (me.zoom >= me.ZOOMBOUNDARY) {
          me.getNearGround()
        } else {
          me.getStatistics()
        }
      })
      //地图缩放
      me.mapInit.addEventListener('zoomend', function(e) {
        me.clearAllOverlays();
        me.zoom = e.target.getZoom();
        me.vertexPoint = e.target.getBounds().getSouthWest();
        me.center = e.target.getCenter();
        if (me.zoom >= me.ZOOMBOUNDARY) {
          me.getNearGround()
        } else {
          me.getStatistics()
        }
      })
    },
    clearAllOverlays() {
      let me = this;
      var allOverlay = me.mapInit.getOverlays();
      for (var i = 0; i < allOverlay.length; i++) {
        me.mapInit.removeOverlay(allOverlay[i]);
      }
    },
    getTypeName(type) {
      return this.groundTypeOptions.filter(x => x.id == type)[0].name
    },
  }
}
